$(function(){
	var data = [{
			COMPANY: '发电厂',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '宿迁',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '福州',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '谏壁',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '酒泉',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '泉州',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '长春',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '汉川',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '金堂',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '肇庆',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '瓮福',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '泰州',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '北塘',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '大同',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '石嘴山',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		//		{
		//			COMPANY: '石嘴山有限',
		//			DJYCS: 0,
		//			GZPYCS: 0,
		//			CZPYCS: 0,
		//			QXYCS: 0,
		//			DQGZYCS: 0
		//		},
		{
			COMPANY: '荥阳',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '兰州',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '天津',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '怀安',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '延吉',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '白城',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '沈阳',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '霍州',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '宿州',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '库车',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '布连',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '哈尔滨',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '克拉玛依',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '承德',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '大连',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '榆次',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '蚌埠',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '九江',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},
		{
			COMPANY: '庄河',
			DJYCS: 0,
			GZPYCS: 0,
			CZPYCS: 0,
			QXYCS: 0,
			DQGZYCS: 0
		},

	];
	var geoCoordMap = {
		"发电厂": [113.22, 33.00],
		"宿迁": [118.28, 33.97],
		"福州": [119.28, 26.11],
		"谏壁": [119.58, 32.16],
		"酒泉": [98.50, 39.74],
		"泉州": [118.68, 24.89],
		"长春": [125.32, 43.83],
		"汉川": [113.84, 30.67],
		"金堂": [104.41, 30.86],
		"肇庆": [112.46, 23.06],
		"瓮福": [113.32, 23.11],
		"泰州": [119.92, 32.46],
		"北塘": [120.25, 31.61],
		"大同": [113.33, 39.50],
		"石嘴山": [106.38, 38.99],
		//		"石嘴山有限": [107.38, 38.55],
		"荥阳": [113.39, 34.79],
		"兰州": [103.84, 36.08],
		"天津": [117.21, 39.10],
		"怀安": [109.01, 33.62],
		"延吉": [129.52, 42.92],
		"白城": [122.82, 45.63],
		"沈阳": [123.40, 41.83],
		"霍州": [111.77, 36.58],
		"宿州": [116.96, 33.67],
		"库车": [82.97, 41.72],
		"布连": [109.61, 39.35],
		"哈尔滨": [126.54, 45.81],
		"克拉玛依": [84.88, 45.59],
		"承德": [117.95, 40.96],
		"大连": [121.61, 38.91],
		"榆次": [112.73, 37.70],
		"蚌埠": [117.39, 32.93],
		"九江": [117.26, 31.83],
		"庄河": [122.96, 39.66],

	};

	var convertData = function(data) {
		var res = [];
		for(var i = 0; i < data.length; i++) {
			var geoCoord = geoCoordMap[data[i]["COMPANY"]];
			if(geoCoord) {
				res.push({
					name: data[i]["COMPANY"],
					value: geoCoord.concat(data[i]["DJYCS"], data[i]["GZPYCS"], data[i]["CZPYCS"], data[i]["QXYCS"], data[i]["DQGZYCS"])
				});
			}
		}
		return res;
	};
	var mapChart = echarts.init(document.getElementById('map'));
	option = {
		backgroundColor: '#fff',
		tooltip: {
			trigger: 'item',
			formatter: function(params) {
				var res = "<div class=\"map-hint\"><div class=\"hint-title\"><span>" + params.data.name + "分公司</span></div>";
				res += "<div class=\"hint-content\"><div class=\"hint-cont\"><div class=\"hint-list\">点检异常数：</div><div class=\"list-number list-num-" + params.data.value[2] + "\">" + params.data.value[2] + "</div></div>";
				res += "<div class=\"hint-content\"><div class=\"hint-cont\"><div class=\"hint-list\">工作票报警数：</div><div class=\"list-number list-num-" + params.data.value[3] + "\">" + params.data.value[3] + "</div></div>";
				res += "<div class=\"hint-content\"><div class=\"hint-cont\"><div class=\"hint-list\">操作票报警数：</div><div class=\"list-number list-num-" + params.data.value[4] + "\">" + params.data.value[4] + "</div></div>";
				res += "<div class=\"hint-content\"><div class=\"hint-cont\"><div class=\"hint-list\">缺陷超期数：</div><div class=\"list-number list-num-" + params.data.value[5] + "\">" + params.data.value[5] + "</div></div>";
				res += "<div class=\"hint-content\"><div class=\"hint-cont\"><div class=\"hint-list\">定期工作超期数：</div><div class=\"list-number list-num-" + params.data.value[6] + "\">" + params.data.value[6] + "</div></div>";
				res += "</div></div>"
				return res
			},
			backgroundColor: "rgba(0,0,0,0)",
			borderWidth: 0,
		},
		legend: {
			orient: 'vertical',
			left: '240',
			bottom: '40',
			data: ['正常', '异常'],
			textStyle: {
				color: '#666'
			},
			icon: 'circle',
			borderColor: '#aaa',
			borderWidth: 1,
			padding: 15,
			borderRadius: 6,
			backgroundColor: "#fff",
			itemWidth: 10,
			itemHeight: 10,
			selected: {
				'异常': true,
				'正常': true
			}
		},
		geo: {
			map: 'china',
			label: {
				emphasis: {
					show: false
				}
			},
			roam: true,
			zoom: 1.4,
			center: [107.38, 34.55],
			itemStyle: {
				normal: {
					areaColor: '#57b7e7',
					borderColor: '#fff'
				},
				emphasis: {
					areaColor: '#74cffc',
					shadowColor:'rgba(0,0,0,0.3)',
					shadowBlur:10,
					shadowOffsetX:6,
					shadowOffsetY:4
				}
			}
		},
		series: [{
				name: '正常',
				type: 'scatter',
				coordinateSystem: 'geo',
				data: getZCdata(data),
				symbolSize: 12,
				label: {
					normal: {
						formatter: '{b}',
						position: 'bottom',
						show: true,
						color: '#272727',
					},
					emphasis: {
						show: true,
						color: '#333',
						position: "bottom"
					}
				},
				itemStyle: {
					normal: {
						color: '#1dfb58'
					}
				}
			},
			{
				name: '异常',
				type: 'effectScatter',
				coordinateSystem: 'geo',
				data: getYCdata(data),
				symbolSize: 10,
				showEffectOn: 'render',
				rippleEffect: {
					brushType: 'stroke'
				},
				hoverAnimation: true,
				label: {
					normal: {
						formatter: '{b}',
						position: 'right',
						show: true
					}
				},
				itemStyle: {
					normal: {
						color: '#fd4128',
						shadowBlur: 10,
						shadowColor: '#333'
					}
				},
				zlevel: 1
			}
		]
	}
	function getYCdata(data) {
		var YCdata = []
		for(var i = 0; i < data.length; i++) {
			if((data[i].DJYCS + data[i].GZPYCS + data[i].CZPYCS + data[i].QXYCS + data[i].DQGZYCS) > 0) {
				var geoCoord = geoCoordMap[data[i]["COMPANY"]];
				if(geoCoord) {
					YCdata.push({
						name: data[i]["COMPANY"],
						value: geoCoord.concat(data[i]["DJYCS"], data[i]["GZPYCS"], data[i]["CZPYCS"], data[i]["QXYCS"], data[i]["DQGZYCS"])
					});
				}
			}
		}
		return YCdata;
	}

	function getZCdata(data) {
		var ZCdata = []
		for(var i = 0; i < data.length; i++) {
			if((data[i].DJYCS + data[i].GZPYCS + data[i].CZPYCS + data[i].QXYCS + data[i].DQGZYCS) == 0) {
				var geoCoord = geoCoordMap[data[i]["COMPANY"]];
				if(geoCoord) {
					ZCdata.push({
						name: data[i]["COMPANY"],
						value: geoCoord.concat(data[i]["DJYCS"], data[i]["GZPYCS"], data[i]["CZPYCS"], data[i]["QXYCS"], data[i]["DQGZYCS"])
					});
				}
			}
		}
		return ZCdata;
	}
	mapChart.setOption(option)
})
